package com.duoec.magichour.controller.web.front;

import com.duoec.magichour.core.annotation.Access;
import com.duoec.magichour.core.web.BaseWebController;
import com.duoec.magichour.dto.response.ArticleListItemDto;
import com.duoec.magichour.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by ycoe on 17/7/8.
 */
@Controller
@RequestMapping("/article")
public class ArticleWebController extends BaseWebController {
    @Autowired
    private ArticleService articleService;

    @Access
    @RequestMapping("/release")
    public ModelAndView myArticle(
            @RequestParam(required = false, defaultValue = "1") int pageNo
    ) {
        Long userId = getUserInfo().getId();
        int pageSize = 20;
        List<ArticleListItemDto> articles = articleService.getUserArticles(userId, userId, pageNo, pageSize);
        addData("articles", articles);
        return view("/front/article/list.ftl");
    }
}
